package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.pojo.Building;
import cn.bgs.pojo.Community;
import cn.bgs.pojo.Portal;
import cn.bgs.service.IBuildingService;
import cn.bgs.vo.CommunityVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 楼栋表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/building")
public class BuildingController {
    @Autowired
    IBuildingService iBuildingService;
    @GetMapping("/test")
    public String test(){
        return "ok";
    }

    @GetMapping({"findinfopc"})
    public PageInfo<CommunityVo> findinfopc(String communityId, String houseuse, String howmany, Integer pagesize, Integer pagenow){
        PageInfo<CommunityVo> page = this.iBuildingService.page1(communityId,houseuse,howmany,pagesize,pagenow);
        return page;
    }

    @GetMapping({"findHousePc"})
    public PageInfo<CommunityVo> findHousePc (String communityId, String houseuse, String state, Integer pagesize, Integer pagenow){
        PageInfo<CommunityVo> pages = this.iBuildingService.page2(communityId, houseuse, state, pagesize, pagenow);
        return pages;
    }

    @PostMapping({"addCommunityPc"})
    public R addCommunityPc(@RequestBody Building forms){
        this.iBuildingService.addCommunityPc(forms);
        return R.ok();
    }

    @GetMapping({"delPc"})
    public R del(Integer id){
        this.iBuildingService.delPc(id);
        return R.ok();
    }

    @PostMapping({"updateBuildPc"})
    public R updateBuildPc(@RequestBody Building formData){
        this.iBuildingService.updateBuildPc(formData);
        return R.ok();
    }

    @PostMapping({"loadPc"})
    public R loadPc(Integer id){
        List<Building> building = this.iBuildingService.loadPc(id);
        return R.ok().data("data", building);
    }

    @PostMapping({"addPortalPc"})
    public R addPortalPc(@RequestBody Portal forms) {
        this.iBuildingService.addPortalPc(forms);
        return R.ok();
    }

    @GetMapping({"delPortalPc"})
    public R delPortalPc(Integer id){
        this.iBuildingService.delPortalPc(id);
        return R.ok();
    }


    @Autowired
    private IBuildingService iBuildingServicep;


    @GetMapping("/appFindBuilding/{communityId}")
    @ApiOperation(value = "app我的房屋(添加房屋的楼栋查询)")
    public R appFindBuilding(@PathVariable Integer communityId){

        List<Building> building = iBuildingServicep.appFindBuilding(communityId);
        if (building != null){
            return R.ok().data("Building",building);
        }else {
            return R.error();
        }
    }


}
